*** This file runs regressions to generate estimates of average effects across different specifications
*** Testing Bootstrapping preperiod means employment, own wage and min wage absorbing all dummies.
*** Here we use states with any minimum wage change in the "all changers group" (include Maine)
*** and the CEP Policy Categories to define the Large Increaser, Small Increaser, and Indexer Treated Groups





capture log close 
clear all
set more off
set trace off


* Set path * If needed change global path to point to directory where files are stored on your computer
*global path "I:/DataSets5/Duncan/Dropbox/Recent Minimum Wage Changes/2020.12 NBER Update/JOLE Precommittment Replication"
global dtadir "$path/Data"
global tabdir "$path/Tables"
global figdir "$path/Figures"
global estdir "$path/Estimates"
global logdir "$path/Logfiles"

log using "$logdir/boot-emp-ow-mw-cep-lowskill-young-baseline-means-seed-789012.log", replace


*Set seed
set seed 789012

* 2) Define bootstrap program for stratified sampling
capture program drop bs_strat
program define bs_strat, rclass

	*------------------------ 1.1 Syntax -------------------------- 

	syntax

	*------------------------ 1.2 Set Up -------------------------- 

	preserve
	
	* Pretreatment means least-skilled employment. Use person weights from ACS
	sum employed if lowskill == 1 & acs == 1 & anychange == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar emp_pre_all_lowskill = `r(mean)'
	
	sum employed if lowskill == 1 & acs == 1 & StatIncreaserLarge == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar  emp_pre_large_lowskill = `r(mean)'
	
	sum employed if lowskill == 1 & acs == 1 & StatIncreaserSmall == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar  emp_pre_small_lowskill = `r(mean)'
	
	sum employed if lowskill == 1 & acs == 1 & indexer == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar  emp_pre_indexer_lowskill = `r(mean)'
	
	* Pretreatment means least-skilled own wage. Use earnings weight from ORG
	sum hourwage if lowskill == 1 & cps == 1 & anychange == 1 & inrange(year,2011,2013) [aw=earnwt]
	return scalar ow_pre_all_lowskill = `r(mean)'
	
	sum hourwage if lowskill == 1 & cps == 1 & StatIncreaserLarge == 1 & inrange(year,2011,2013) [aw=earnwt]
	return scalar ow_pre_large_lowskill = `r(mean)'
	
	sum hourwage if lowskill == 1 & cps == 1 & StatIncreaserSmall == 1 & inrange(year,2011,2013) [aw=earnwt]
	return scalar ow_pre_small_lowskill = `r(mean)'
	
	sum hourwage if lowskill == 1 & cps == 1 & indexer == 1 & inrange(year,2011,2013) [aw=earnwt]
	return scalar ow_pre_indexer_lowskill = `r(mean)'
	
	* Pretreatment means least-skilled minimum wage. Use person weights from Basic Monthly Survey
	sum effectiveminwage if lowskill == 1 & cps == 1 & anychange == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar mw_pre_all_lowskill = `r(mean)'
	
	sum effectiveminwage if lowskill == 1 & cps == 1 & StatIncreaserLarge == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar mw_pre_large_lowskill = `r(mean)'
	
	sum effectiveminwage if lowskill == 1 & cps == 1 & StatIncreaserSmall == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar mw_pre_small_lowskill = `r(mean)'
	
	sum effectiveminwage if lowskill == 1 & cps == 1 & indexer == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar mw_pre_indexer_lowskill = `r(mean)'
	
	
	
	
	* Pretreatment means young employment. Use person weights from ACS
	sum employed if young == 1 & acs == 1 & anychange == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar emp_pre_all_young = `r(mean)'
	
	sum employed if young == 1 & acs == 1 & StatIncreaserLarge == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar  emp_pre_large_young = `r(mean)'
	
	sum employed if young == 1 & acs == 1 & StatIncreaserSmall == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar  emp_pre_small_young = `r(mean)'
	
	sum employed if young == 1 & acs == 1 & indexer == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar  emp_pre_indexer_young = `r(mean)'
	
	* Pretreatment means young own wage. Use earnings weight from ORG
	sum hourwage if young == 1 & cps == 1 & anychange == 1 & inrange(year,2011,2013) [aw=earnwt]
	return scalar ow_pre_all_young = `r(mean)'
	
	sum hourwage if young == 1 & cps == 1 & StatIncreaserLarge == 1 & inrange(year,2011,2013) [aw=earnwt]
	return scalar ow_pre_large_young = `r(mean)'
	
	sum hourwage if young == 1 & cps == 1 & StatIncreaserSmall == 1 & inrange(year,2011,2013) [aw=earnwt]
	return scalar ow_pre_small_young = `r(mean)'
	
	sum hourwage if young == 1 & cps == 1 & indexer == 1 & inrange(year,2011,2013) [aw=earnwt]
	return scalar ow_pre_indexer_young = `r(mean)'
	
	* Pretreatment means young minimum wage. Use person weights from Basic Monthly Survey
	sum effectiveminwage if young == 1 & cps == 1 & anychange == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar mw_pre_all_young = `r(mean)'
	
	sum effectiveminwage if young == 1 & cps == 1 & StatIncreaserLarge == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar mw_pre_large_young = `r(mean)'
	
	sum effectiveminwage if young == 1 & cps == 1 & StatIncreaserSmall == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar mw_pre_small_young = `r(mean)'
	
	sum effectiveminwage if young == 1 & cps == 1 & indexer == 1 & inrange(year,2011,2013) [aw=perwt]
	return scalar mw_pre_indexer_young = `r(mean)'
	
	restore
	
end
				   


*****************************************************************************************************
************					   3. Set up data							            ************
***************************************************************************************************** 


tempfile acs
tempfile cps

*** Assemble relevant years of the ACS 
use "$dtadir/ACS-2019.dta", clear 

drop if year < 2011 

*** Drop seniors
drop if age >= 65 | age < 16
drop if empstat == 0

*** Construct economic outcomes of interest 
gen employed = 0
replace employed = 1 if empstat == 1

**** Construct education variables
gen dropout = 0 
replace dropout = 1 if educ < 6
gen highschool = 0 
replace highschool = 1 if educ == 6
gen somecollege = 0
replace somecollege = 1 if educ >= 7 & educ < 10
gen collegeplus = 0
replace collegeplus = 1 if educ >= 10

*** Merge in HPI data
merge m:1 statefip year using "$dtadir/HPI_acs_2019.dta"
drop if _merge == 2
drop _merge

replace HPI = HPI/1000

*** Merge in personal income data
merge m:1 statefip year using "$dtadir/PersonalIncome_acs_2019.dta"
gen lnPersonalIncome = ln(PersonalIncome)
drop if _merge == 2
drop _merge

gen time = year

** creates mid skill employment rate 
gen group = 0 
replace group = 1 if (age <= 30 & age > 21 & highschool == 1) | (age > 30 & age <= 45 & dropout == 1) | (age > 45 & age < 65 & dropout == 1) 

egen stateempD = mean(employed) if group == 1, by(year statefip) 
egen stateempE = max(stateempD), by(year statefip) 

gen lowskill = 0 
replace lowskill = 1 if inrange(age,16,25) & dropout == 1 

gen young = 0 
replace young = 1 if inrange(age,16,21)

gen primeage = 0
replace primeage = 1 if inrange(age,26,54)

keep if young == 1 | lowskill == 1

gen acs = 1
gen cps = 0

keep employed year statefip lnPersonalIncome HPI educ age stateempE young lowskill acs cps perwt time

compress

save `acs', replace



*** Assemble relevant years of the basic monthly CPS
use "$dtadir/CPS-2019.dta", clear

drop if year < 2011

*** Drop seniors
drop if age >= 65 | age < 16
drop if empstat == 0

*** Construct economic outcomes of interest 

* if empstat = 10: "At work"
* if empstat = 12: "employed, not at work last week

gen employed = 0
replace employed = 1 if  empstat == 10 |  empstat == 12

*** Assume that armed forces are employed
replace employed = 1 if empstat == 1

**** Construct education variables
gen dropout = 0 
replace dropout = 1 if educ < 73
gen highschool = 0 
replace highschool = 1 if educ == 73
gen somecollege = 0
replace somecollege = 1 if educ >= 81 & educ <= 92
gen collegeplus = 0
replace collegeplus = 1 if educ >= 111

gen quarter = 1 if inlist(month,1,2,3)
replace quarter = 2 if inlist(month,4,5,6)
replace quarter = 3 if inlist(month,7,8,9)
replace quarter = 4 if inlist(month,10,11,12)

gen time = (100*year) + month

*** Merge in HPI data
merge m:1 statefip year quarter using "$dtadir/HPI_2019.dta"
drop if _merge == 2
drop _merge

replace HPI = HPI/1000

*** Merge in personal income data
merge m:1 statefip year quarter using "$dtadir/PersonalIncome_2019.dta"
gen lnPersonalIncome = ln(PersonalIncome)
drop if _merge == 2
drop _merge

** creates mid-skill employment rate 
gen group = 0 
replace group = 1 if (age <= 30 & age > 21 & highschool == 1) | (age > 30 & age <= 45 & dropout == 1) | (age > 45 & age < 65 & dropout == 1) 

egen stateempD = mean(employed) if group == 1, by(year month statefip) 
egen stateempE = max(stateempD), by(year month statefip) 

gen lowskill = 0 
replace lowskill = 1 if inrange(age,16,25) & dropout == 1

gen young = 0 
replace young = 1 if inrange(age,16,21)

gen primeage = 0
replace primeage = 1 if inrange(age,26,54)

keep if lowskill == 1 | young == 1

*** Generate indicators if receive tips/overtime, paid hourly, or have wage rates imputed
gen tippedorovertime = otpay == 2
gen hourly = paidhour == 2 
gen notimputed = qhourwag == 0 
gen notimputedB = (qhourwag == 0 & qearnwee == 0)

*** Keep only people eligible for the ORG sample for hourly wage regressions
replace hourwage =. if eligorg != 1

*** Keep only people are employed for hourly wage regressions
replace hourwage =. if employed != 1

*** Keep only people paid by the hour for hourly wage regressions
replace hourwage =. if hourly != 1

*** Keep only people who do not have imputed wage rates for hourly wage regressions
replace hourwage =. if notimputed != 1

* Adjust NIU cases for hourly wages for hourly wage regressions
replace hourwage =. if hourwage == 999.99


gen acs = 0
gen cps = 1

gen perwt = wtfinl

keep employed hourwage year month statefip lnPersonalIncome HPI time educ age stateempE lowskill young acs cps perwt earnwt

compress

append using `acs'

* generate post variable 
cap drop post 
gen post = 0 if inrange(year,2011,2013) 
replace post = 1 if inrange(year,2015,2019)

* Keep only needed observations to reduce memory
keep if post == 0
keep if lowskill == 1 | young == 1


* merge in policy categories 
cap drop originaltype-increase5 
merge m:1 statefip using "$dtadir/min_wage_variables_for_ACS_and_CPS_analysis.dta", nogen keepusing(originaltype jan*min) 

cap drop indexer StatIncreaserLarge StatIncreaserSmall statutoryincreasein2014or2015 statutoryincreasein2014to2017 statutoryincreasein2014to2018

gen indexer = 0 
gen StatIncreaserLarge = 0 
gen StatIncreaserSmall = 0 
gen statutoryincreasein2014or2015 = 0
gen statutoryincreasein2014to2018 = 0

* CEP Categories
replace indexer = 1 if originaltype == "Indexer" 
replace statutoryincreasein2014or2015 = 1 if (jan2016min - jan2013min) > 0 & indexer == 0 
replace StatIncreaserLarge = 1 if indexer == 0 & (jan2015min - jan2013min) >= 1 & (jan2016min - jan2013min) != . 
replace StatIncreaserSmall = 1 if indexer == 0 & statutoryincreasein2014or2015 == 1 & StatIncreaserLarge == 0 

* Generate January minimum wage variable
gen effectiveminwage =.
forvalues i=2011/2019 {
	replace effectiveminwage = jan`i'min if year == `i'
}

* Generate any change indicator
gen anychange = 0
replace anychange = 1 if jan2019min - jan2011min > 0

* Generate policygroup variable for doing proportional sampling correctly
gen policygroup = 1
replace policygroup = 2 if indexer == 1
replace policygroup = 3 if StatIncreaserSmall == 1
replace policygroup = 4 if StatIncreaserLarge == 1

compress


cd "$estdir/Bootstrap/seed-789012"

timer clear
timer on 1

* Run bootstrap command for stratified sampling for all means, ACS means, and CPS means for all changer states, large increasers, small increasers, and indexers.

bootstrap ///
emp_pre_allchange_lowskill=r(emp_pre_all_lowskill) emp_pre_large_lowskill=r(emp_pre_large_lowskill) emp_pre_small_lowskill=r(emp_pre_small_lowskill) emp_pre_index_lowskill=r(emp_pre_indexer_lowskill) ///
emp_pre_allchange_young=r(emp_pre_all_young) emp_pre_large_young=r(emp_pre_large_young) emp_pre_small_young=r(emp_pre_small_young) emp_pre_index_young=r(emp_pre_indexer_young) ///
ow_pre_allchange_lowskill=r(ow_pre_all_lowskill) ow_pre_large_lowskill=r(ow_pre_large_lowskill) ow_pre_small_lowskill=r(ow_pre_small_lowskill) ow_pre_index_lowskill=r(ow_pre_indexer_lowskill) ///
mw_pre_allchange_lowskill=r(mw_pre_all_lowskill) mw_pre_large_lowskill=r(mw_pre_large_lowskill) mw_pre_small_lowskill=r(mw_pre_small_lowskill) mw_pre_index_lowskill=r(mw_pre_indexer_lowskill) ///
ow_pre_allchange_young=r(ow_pre_all_young) ow_pre_large_young=r(ow_pre_large_young) ow_pre_small_young=r(ow_pre_small_young) ow_pre_index_young=r(ow_pre_indexer_young) ///
mw_pre_allchange_young=r(mw_pre_all_young) mw_pre_large_young=r(mw_pre_large_young) mw_pre_small_young=r(mw_pre_small_young) mw_pre_index_young=r(mw_pre_indexer_young), ///
rep(100) cluster(statefip) strata(policygroup) idcluster(stateid) saving("boot-emp-ow-mw-cep-lowskill-young-baseline-means", replace): bs_strat

* Display all bootstrap statistics
*estat bootstrap, all

* Save data from original call with data as is.
mat res = r(table) 
svmat res, names(col)
gen stat = ""
gen n = _n
replace stat = "beta" if n == 1
replace stat = "boot_se" if n == 2
replace stat = "z-score" if n == 3
replace stat = "pval" if n == 4
replace stat = "lo_ci" if n == 5
replace stat = "hi_ci" if n == 6

keep emp_pre_allchange_lowskill-stat

label var emp_pre_allchange_lowskill "Employment Low-Skill Average 2011-2013 All Changers"
label var emp_pre_large_lowskill "Employment Low-Skill Average 2011-2013 Large Increasers"
label var emp_pre_small_lowskill "Employment Low-Skill Average 2011-2013 Small Increasers"
label var emp_pre_index_lowskill "Employment Low-Skill Average 2011-2013 Indexers"

label var emp_pre_allchange_young "Employment Young Average 2011-2013 All Changers"
label var emp_pre_large_young "Employment Young Average 2011-2013 Large Increasers"
label var emp_pre_small_young "Employment Young Average 2011-2013 Small Increasers"
label var emp_pre_index_young "Employment Young Average 2011-2013 Indexers"

label var ow_pre_allchange_lowskill "Own Wage Low-Skill Average 2011-2013 All Changers"
label var ow_pre_large_lowskill "Own Wage Low-Skill Average 2011-2013 Large Increasers"
label var ow_pre_small_lowskill "Own Wage Low-Skill Average 2011-2013 Small Increasers"
label var ow_pre_index_lowskill "Own Wage Low-Skill Average 2011-2013 Indexers"

label var mw_pre_allchange_lowskill "Min Wage Low-Skill Average 2011-2013 All Changers"
label var mw_pre_large_lowskill "Min Wage Low-Skill Average 2011-2013 Large Increasers"
label var mw_pre_small_lowskill "Min Wage Low-Skill Average 2011-2013 Small Increasers"
label var mw_pre_index_lowskill "Min Wage Low-Skill Average 2011-2013 Indexers"

label var ow_pre_allchange_young "Own Wage Young Average 2011-2013 All Changers"
label var ow_pre_large_young "Own Wage Young Average 2011-2013 Large Increasers"
label var ow_pre_small_young "Own Wage Young Average 2011-2013 Small Increasers"
label var ow_pre_index_young "Own Wage Young Average 2011-2013 Indexers"

label var mw_pre_allchange_young "Min Wage Young Average 2011-2013 All Changers"
label var mw_pre_large_young "Min Wage Young Average 2011-2013 Large Increasers"
label var mw_pre_small_young "Min Wage Young Average 2011-2013 Small Increasers"
label var mw_pre_index_young "Min Wage Young Average 2011-2013 Indexers"


* Add labels to bootstrap code sample
cap drop policycat sample switchers postmin postmax

drop if missing(stat)

save "coef-emp-ow-mw-cep-lowskill-young-baseline-means", replace


*  Add labels to bootstrap code sample
use "boot-emp-ow-mw-cep-lowskill-young-baseline-means", clear
gen iteration = _n

label var emp_pre_allchange_lowskill "Employment Low-Skill Average 2011-2013 All Changers"
label var emp_pre_large_lowskill "Employment Low-Skill Average 2011-2013 Large Increasers"
label var emp_pre_small_lowskill "Employment Low-Skill Average 2011-2013 Small Increasers"
label var emp_pre_index_lowskill "Employment Low-Skill Average 2011-2013 Indexers"

label var emp_pre_allchange_young "Employment Young Average 2011-2013 All Changers"
label var emp_pre_large_young "Employment Young Average 2011-2013 Large Increasers"
label var emp_pre_small_young "Employment Young Average 2011-2013 Small Increasers"
label var emp_pre_index_young "Employment Young Average 2011-2013 Indexers"

label var ow_pre_allchange_lowskill "Own Wage Low-Skill Average 2011-2013 All Changers"
label var ow_pre_large_lowskill "Own Wage Low-Skill Average 2011-2013 Large Increasers"
label var ow_pre_small_lowskill "Own Wage Low-Skill Average 2011-2013 Small Increasers"
label var ow_pre_index_lowskill "Own Wage Low-Skill Average 2011-2013 Indexers"

label var mw_pre_allchange_lowskill "Min Wage Low-Skill Average 2011-2013 All Changers"
label var mw_pre_large_lowskill "Min Wage Low-Skill Average 2011-2013 Large Increasers"
label var mw_pre_small_lowskill "Min Wage Low-Skill Average 2011-2013 Small Increasers"
label var mw_pre_index_lowskill "Min Wage Low-Skill Average 2011-2013 Indexers"

label var ow_pre_allchange_young "Own Wage Young Average 2011-2013 All Changers"
label var ow_pre_large_young "Own Wage Young Average 2011-2013 Large Increasers"
label var ow_pre_small_young "Own Wage Young Average 2011-2013 Small Increasers"
label var ow_pre_index_young "Own Wage Young Average 2011-2013 Indexers"

label var mw_pre_allchange_young "Min Wage Young Average 2011-2013 All Changers"
label var mw_pre_large_young "Min Wage Young Average 2011-2013 Large Increasers"
label var mw_pre_small_young "Min Wage Young Average 2011-2013 Small Increasers"
label var mw_pre_index_young "Min Wage Young Average 2011-2013 Indexers"

label var iteration "Bootstrap Iteration Number"

save "boot-emp-ow-mw-cep-lowskill-young-baseline-means.dta", replace

di "Sample: lowskill and young. Switcher states: switchers. pre start: 2011 pre end: 2013. Done" 


timer off 1
timer list 1
log close

